package com.wd.jetpack.ui.viewmodel

import androidx.databinding.ObservableField
import com.wd.jetpack.model.ArticleBean

/**
 * 列表行item
 */
class ListItemViewModel {
    var thumbnailPic = ObservableField<String>("")
    var authorName = ObservableField<String>("")
    var title = ObservableField<String>("title")
    lateinit var item: ArticleBean

    fun set(itemData: ArticleBean): ListItemViewModel {
        item = itemData
        thumbnailPic.set(itemData.thumbnail_pic_s)
        authorName.set(itemData.author_name)
        title.set(itemData.title)
        return this
    }

    //安全的刷新方式, Observable 已做校验，前后字符串一致不会刷新
    //有数据变化时可调用此方法进行刷新
    fun notifyData() {
        thumbnailPic.notifyChange()
        authorName.notifyChange()
        title.notifyChange()
    }
}